/*
 * @Author: LVGRAPE
 * @LastEditors: LVGRAPE
 */
#ifndef __DRV_PIN_H__
#define __DRV_PIN_H__

#include <rtthread.h>
#include <rthw.h>
#include "at32f413.h"
#include "board.h"

#ifdef __cplusplus
extern "C" {
#endif


typedef enum
{
    PIN_MODE_INPUT,
    PIN_MODE_INPUT_PULLUP,
    PIN_MODE_INPUT_PULLDOWN,
    PIN_MODE_OUTPUT_PP,
    PIN_MODE_OUTPUT_OD,
    PIN_MODE_MUX,
    PIN_MODE_ANALOG,
} pin_mode_type;
typedef enum
{
    PA0 = 0,
    PA1,
    PA2,
    PA3,
    PA4,
    PA5,
    PA6,
    PA7,
    PA8,
    PA9,
    PA10,
    PA11,
    PA12,
    PA13,
    PA14,
    PA15,
    PB0,
    PB1,
    PB2,
    PB3,
    PB4,
    PB5,
    PB6,
    PB7,
    PB8,
    PB9,
    PB10,
    PB11,
    PB12,
    PB13,
    PB14,
    PB15,
    PC0,
    PC1,
    PC2,
    PC3,
    PC4,
    PC5,
    PC6,
    PC7,
    PC8,
    PC9,
    PC10,
    PC11,
    PC12,
    PC13,
    PC14,
    PC15,
    PD0,
    PD1,
    PD2,
    PD3,
    PD4,
    PD5,
    PD6,
    PD7,
    PD8,
    PD9,
    PD10,
    PD11,
    PD12,
    PD13,
    PD14,
    PD15,
    // PE0,
    // PE1,
    // PE2,
    // PE3,
    // PE4,
    // PE5,
    // PE6,
    // PE7,
    // PE8,
    // PE9,
    // PE10,
    // PE11,
    // PE12,
    // PE13,
    // PE14,
    // PE15,
    PF0,
    PF1,
    PF2,
    PF3,
    PF4,
    PF5,
    PF6,
    PF7,
    PF8,
    PF9,
    PF10,
    PF11,
    PF12,
    PF13,
    PF14,
    PF15,
} pin_index_t;
typedef enum{
    PIN_LOW = 0,
    PIN_HIGH = 1,
}pin_state;
gpio_type *pin_get_port(pin_index_t pin);
uint32_t pin_get_pin(pin_index_t pin);
void pin_mode(pin_index_t pin, pin_mode_type mode);
void pin_write(pin_index_t pin, confirm_state value);
pin_state pin_read(pin_index_t pin);
void at_pin_mode_input(gpio_type *port, uint32_t pins);
void at_pin_mode_pp(gpio_type *port, uint32_t pins);
void at_pin_mode_od(gpio_type *port, uint32_t pins);

#define IO_SET(port, pin) (port)->scr = (pin)
#define IO_RESET(port, pin) (port)->clr = (pin)
#define IO_READ(port, pins) (pins == (pins & (port)->idt))

void generate_led_blink_value(void);
uint8_t get_blinkSlowVal(void);
uint8_t get_blinkFastVal(void);
uint8_t get_blinkBreathVal(void);
uint8_t get_blinkDotVal(void);
int clock_information(void);
#ifdef __cplusplus
}
#endif

#endif /* __DRV_PIN_H__ */
